#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
#define rep(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
#define per(i,r,l) for(int i=(r),i##end=(l);i>=i##end;--i)
#define ll long long
#define int ll
#define double long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define popcnt __builtin_popcount
#define rbtree(way) tree<way,null_type,less<way>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
const int maxn=5e4+10,maxm=1e3+10,mod=998244353,inf=INT_MAX;
inline int ksm(int x,int k,int mod=mod){
	int ans=1;
	for(x%=mod;k;k>>=1,x=x*x%mod) if(k&1) ans=ans*x%mod;
	return ans;
}

int n,m,ans,p[maxm],f[maxn][maxm];
string S,T;

signed main(){
	freopen("neck.in","r",stdin),freopen("neck.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>S>>T,n=S.size(),m=T.size(),S=' '+S,T=' '+T;
	rep(i,2,m){
		for(p[i]=p[i-1];p[i]&&T[i]!=T[p[i]+1];p[i]=p[p[i]]);
		if(T[i]==T[p[i]+1]) ++p[i];
	}
	rep(i,0,n) rep(j,0,m) f[i][j]=-inf;
	f[0][0]=0;
	rep(i,1,n){
		rep(j,0,m-1) f[i][j]=f[i-1][j];
		per(j,m-1,1) if(S[i]!=T[j+1]) f[i-1][p[j]]=max(f[i-1][p[j]],f[i-1][j]);
		if(S[i]!=T[1]) f[i][0]=max(f[i][0],f[i-1][0]+1);
		rep(j,1,m-1) if(S[i]==T[j]) f[i][j]=max(f[i][j],f[i-1][j-1]+1);
	}
	rep(i,0,m-1) ans=max(ans,f[n][i]);
	cout<<ans;
	return 0;
}
